/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using VSLangProj;
using DaveSexton.DocProject.Resources;

namespace DaveSexton.DocProject
{
	public sealed class ProjectSourceCollection : KeyedCollection<VSSourceProject, VSSourceProject>
	{
		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="ProjectSourceCollection" /> class.
		/// </summary>
		internal ProjectSourceCollection()
			: base(new ProjectComparer<VSSourceProject>())
		{
		}
		#endregion

		#region Methods
		protected override VSSourceProject GetKeyForItem(VSSourceProject item)
		{
			return item;
		}

		protected override void InsertItem(int index, VSSourceProject item)
		{
			if (item == null)
				throw new ArgumentNullException("item");

			if (Contains(item))
				throw new ArgumentException(Errors.DuplicateItems, "item");

			base.InsertItem(index, item);
		}

		protected override void SetItem(int index, VSSourceProject item)
		{
			if (item == null)
				throw new ArgumentNullException("item");

			int i = IndexOf(item);

			if (i != index && i > -1)
				throw new ArgumentException(Errors.DuplicateItems);

			base.SetItem(index, item);
		}
		#endregion
	}
}
